package com.serookie.controller;

import com.serookie.entity.GoodsDetails;
import com.serookie.entity.Result;
import com.serookie.service.GoodsDetailsService;
import com.serookie.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.ResultType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author kevintam
 * @version 1.0
 * @date 2021/5/24 21:54
 */
@RestController
@Api(value="商品详情接口",tags={"商品详情接口"})
@RequestMapping("/admin/details")
public class GoodsDetailsController{
    @Autowired
    private GoodsDetailsService detailsService;

    @GetMapping("/all")
    @ApiOperation("商品详情")
    public Result all(){
        List<GoodsDetails> all = detailsService.all();
        return Result.ok().message("操作成功").data("data",all);
    }
    @PostMapping("/save")
    @ApiOperation("上传商品详情")
    public Result save(GoodsDetails goodsDetails){
        Boolean flag = detailsService.save(goodsDetails);
        if(flag){
            return Result.ok().message("操作成功");
        }
        return Result.error().message("操作失败");
    }
    @PostMapping("/update")
    @ApiOperation("修改商品详情")
    public Result update(GoodsDetails goodsDetails){
        Boolean flag = detailsService.updateDetails(goodsDetails);
        if(flag){
            return Result.ok().message("操作成功");
        }
        return Result.error().message("操作失败");
    }
    @PostMapping("/del/{goodsId}")
    @ApiOperation("删除商品详情")
    public Result del(@PathVariable("goodsId")Integer goodsId){
        Boolean flag = detailsService.delDetails(goodsId);
        if(flag){
            return Result.ok().message("操作成功");
        }
        return Result.error().message("操作失败");
    }
}
